package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.coupon.CouponCreateBO;
import com.cskaoyan.bean.coupon.CouponDeleteBO;
import com.cskaoyan.bean.coupon.CouponUpdateBO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.MarketCoupon;
import com.cskaoyan.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author chenai
 * @description TODO
 * @date 2022-06-06 10:33
 */
@RestController
@RequestMapping("admin/coupon")
public class CouponController {

    @Autowired
    CouponService couponService;

    //http://localhost:8083/admin/couple/list?limit=0
    //http://localhost:8083/admin/couple/list?page=1&limit=20&name=1&sort=add_time&order=desc
    //http://localhost:8083/admin/coupon/list?page=1&limit=20&name=1&type=0&status=0&sort=add_time&order=desc
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, String name, Short type) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo = couponService.list(baseParam, name, type);
        return baseRespVo;
    }

    @RequestMapping("create")
    public BaseRespVo create(@RequestBody() CouponCreateBO couponCreateBO) throws IOException {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo = couponService.create(couponCreateBO);
        return baseRespVo;
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody() CouponUpdateBO couponUpdateBO) throws IOException {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo = couponService.update(couponUpdateBO);
        return baseRespVo;
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody() CouponDeleteBO couponDeleteBO) throws IOException {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo = couponService.delete(couponDeleteBO);
        return baseRespVo;
    }

    @RequestMapping("listuser")
    public BaseRespVo listuser(BaseParam baseParam, Integer couponId) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo = couponService.listuser(baseParam, couponId);
        return baseRespVo;
    }

    @RequestMapping("read")
    public BaseRespVo read(Integer id) {
        BaseRespVo baseRespVo = new BaseRespVo();
        baseRespVo = couponService.read(id);
        return baseRespVo;
    }
}
